*************************************************************************************
*************************************************************************************
** Replication code for:
** LJZ-2018-006 IQ/Intelligence Stereotypes
** US Public Perceptions of an Intelligence Quotient Test Score Gap Between Black Americans and White Americans 
** Preregistration: https://osf.io/u6tgk/?view_only=0babcedf1a7246f5ad91bd4539320b24 
** Stata 15
*************************************************************************************
*************************************************************************************

tab IC, mi
tab Finished, mi
sum Durationinseconds, de

************************************************************************
** Run to remove cases with shared MTurk IDs, IP addresses, or latitude/longitude combinations
************************************************************************

tab LJid if dupID==1 | dupIP==1 | dupGEO==1
drop     if dupID==1 | dupIP==1 | dupGEO==1
tab LJid 

************************************************************************
** Code demographics
************************************************************************

tab D_RAC, mi
gen Rwhite = 0
replace Rwhite = 1 if D_RAC=="White"
tab D_RAC Rwhite, mi

tab D_SEX, mi
gen female = 0
replace female = 1 if D_SEX=="Female"
gen male = 0
replace male = 1 if D_SEX=="Male"
tab D_SEX female, mi
tab D_SEX male, mi

tab D_EDU, mi
gen educ = 0
replace educ = 0.25 if D_EDU=="High school degree"
replace educ = 0.50 if D_EDU=="2-year college degree"
replace educ = 0.75 if D_EDU=="4-year college degree"
replace educ = 1.00 if D_EDU=="More than a 4-year college degree"
tab D_EDU educ, mi

gen educ4 = educ
recode educ4 (0=0.25)
replace educ4 = (educ4-0.25)/0.75
sum educ4
tab D_EDU educ4, mi

pwcorr educ educ4, sig obs

tab D_AGE, mi
gen age = 0
replace age = 1/6 if D_AGE=="25 - 29"
replace age = 2/6 if D_AGE=="30 - 34"
replace age = 3/6 if D_AGE=="35 - 39"
replace age = 4/6 if D_AGE=="40 - 49"
replace age = 5/6 if D_AGE=="50 - 59"
replace age = 6/6 if D_AGE=="60 or older"
tab D_AGE age, mi

tab D_PTY, mi
gen DEM = 0
gen GOP = 0
gen PTY_NO = 0
replace DEM = 1 if D_PTY=="Democrat"
replace GOP = 1 if D_PTY=="Republican"
replace PTY_NO = 1 if D_PTY!="Democrat" & D_PTY!="Republican"
tab D_PTY DEM, mi
tab D_PTY GOP, mi
tab D_PTY PTY_NO, mi

tab D_IDE, mi
gen consv01 = .
replace consv01 = 0/6 if D_IDE=="Extremely liberal"
replace consv01 = 1/6 if D_IDE=="Liberal"
replace consv01 = 2/6 if D_IDE=="Slightly liberal"
replace consv01 = 3/6 if D_IDE=="Moderate, middle of the road"
replace consv01 = 4/6 if D_IDE=="Slightly conservative"
replace consv01 = 5/6 if D_IDE=="Conservative"
replace consv01 = 6/6 if D_IDE=="Extremely conservative"
tab D_IDE consv01, mi

gen lib2 = 0
replace lib2 = 1 if D_IDE=="Extremely liberal"
replace lib2 = 1 if D_IDE=="Liberal"
tab D_IDE lib2, mi

gen con2 = 0
replace con2 = 1 if D_IDE=="Conservative"
replace con2 = 1 if D_IDE=="Extremely conservative"
tab D_IDE con2, mi

************************************************************************
** Keep only white participants
************************************************************************

keep if Rwhite==1 // Run this for the Whites only analysis
tab LJid

************************************************************************
** Attention check: 98% for Whites 
************************************************************************

tab ATT, mi

************************************************************************
** Code variables
************************************************************************

tab IQbw, mi
gen IQwb = 0
replace IQwb = 1 if IQbw=="On average, Black Americans score lower on IQ tests than White Americans score."
tab IQbw IQwb
tab IQbw if IQwb==0, mi
tab IQbw if IQwb==1, mi

tab INTELbw, mi
gen INTELwb = .
replace INTELwb = 0 if INTELbw=="On average, Black Americans are more intelligent than White Americans are."
replace INTELwb = 0 if INTELbw=="On average, Black Americans are equally as intelligent as White Americans are."
replace INTELwb = 1 if INTELbw=="On average, Black Americans are less intelligent than White Americans are."
tab INTELbw INTELwb, mi
tab INTELbw if INTELwb==0, mi
tab INTELbw if INTELwb==1, mi

tab MATHaw, mi
gen MATHasian = 0
replace MATHasian = 1 if MATHaw=="On average, Asian Americans are better at math than White Americans are."
tab MATHaw MATHasian, mi
tab MATHaw if MATHasian==0, mi
tab MATHaw if MATHasian==1, mi

tab IQwell, mi
gen IQwell01 = .
replace IQwell01 = 0.00 if IQwell=="Not well at all"
replace IQwell01 = 0.25 if IQwell=="Slightly well"
replace IQwell01 = 0.50 if IQwell=="Moderately well"
replace IQwell01 = 0.75 if IQwell=="Very well"
replace IQwell01 = 1.00 if IQwell=="Extremely well"
tab IQwell IQwell01, mi

tab Hard
gen hard01 = .
replace hard01 = 0.00 if Hard=="None of the gap"
replace hard01 = 0.25 if Hard=="A small part of the gap"
replace hard01 = 0.50 if Hard=="A moderate part of the gap"
replace hard01 = 0.75 if Hard=="A large part of the gap"
replace hard01 = 1.00 if Hard=="All of the gap"
tab Hard hard01, mi

tab1 testIQ1 testIQ2 testMATH
tab1 testIQ1 testIQ2 testMATH, mi

tab IQMath_DO
gen IQ50 = 0 if IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2"
tab IQ50
tab testIQ1
tab testIQ2
recode IQ50 (0=1) if testIQ1==50 | testIQ2==50
tab IQMath_DO IQ50 
gen math50 = 0 if IQMath_DO=="testMATH"
tab testMATH
recode math50 (0=1) if testMATH==50
tab IQMath_DO math50
tab1 IQ50 math50

gen IQestimate = testIQ1 if IQMath_DO=="testIQ1"
replace IQestimate = testIQ2 if IQMath_DO=="testIQ2"
tab testIQ1 IQestimate if testIQ1!=., mi
tab testIQ2 IQestimate if testIQ2!=., mi

ttest testMATH = IQestimate, unp une

************************************************************************
** Demographics
************************************************************************

tab1 D_SEX D_EDU D_AGE D_PTY D_IDE, nol mi

************************************************************************
** Analysis 
************************************************************************

tab1 IQbw INTELbw MATHaw IQwell Hard, mi

tab IQwb, mi
ci prop IQwb

tab INTELwb, mi
ci prop INTELwb

tab IQwb INTELwb, mi
di 47/49
di 32/119

ci prop IQwb if INTELwb==1
ci prop IQwb if INTELwb==0
prtest IQwb, by(INTELwb)

ci prop INTELwb if IQwb==1
ci prop INTELwb if IQwb==0

************************************************************************
** Comparison of proportions hypothetical IQ test / math test
************************************************************************

prtest IQ50==math50
tab IQ50
tab math50
tab IQestimate
tab testMATH

************************************************************************
** Respondents who indicated W>B in IQ
************************************************************************

sum MATHasian hard01 IQestimate IQwell01

// math asian
tab MATHasian
prtest MATHasian, by(IQwb) level(84)

// hard
tab hard01
ttest hard01, by(IQwb) une unp level(84)

// estimate of IQ gap
tab IQestimate
ttest IQestimate, by(IQwb) une unp level(84)

ci mean IQestimate if IQwb==1, level(84)
ci mean IQestimate if IQwb==0, level(84)

// iq well
tab IQwell01
ttest IQwell01, by(IQwb) une unp level(84)

************************************************************************
** respondents who indicated W>B in intelligence
************************************************************************

// math asian
tab MATHasian
prtest MATHasian, by(INTELwb) level(84)

// hard
tab hard01
ttest hard01, by(INTELwb) une unp level(84)

// better estimate of IQ gap
tab IQestimate
ttest IQestimate, by(INTELwb) une unp level(84)

ci mean IQestimate if INTELwb==1, level(84)
ci mean IQestimate if INTELwb==0, level(84)

// iq well
tab IQwell01
ttest IQwell01, by(INTELwb) une unp level(84)

************************************************************************
** Table 2 estimates for the hypothetical IQ test
************************************************************************

tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2"), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (D_IDE=="Extremely liberal" | D_IDE=="Liberal" | D_IDE=="Slightly liberal"), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (D_IDE=="Extremely conservative" | D_IDE=="Conservative"| D_IDE=="Slightly conservative"), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score higher on IQ tests than White Americans score."), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score the same on IQ tests as White Americans score."), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score lower on IQ tests than White Americans score."), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are more intelligent than White Americans are."), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are equally as intelligent as White Americans are."), mi
tab IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are less intelligent than White Americans are."), mi


ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2"), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (D_IDE=="Extremely liberal" | D_IDE=="Liberal" | D_IDE=="Slightly liberal"), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (D_IDE=="Extremely conservative" | D_IDE=="Conservative"| D_IDE=="Slightly conservative"), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score higher on IQ tests than White Americans score."), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score the same on IQ tests as White Americans score."), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score lower on IQ tests than White Americans score."), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are more intelligent than White Americans are."), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are equally as intelligent as White Americans are."), level(84)
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are less intelligent than White Americans are."), level(84)

ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (D_IDE=="Extremely liberal" | D_IDE=="Liberal" | D_IDE=="Slightly liberal")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (D_IDE=="Extremely conservative" | D_IDE=="Conservative"| D_IDE=="Slightly conservative")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score higher on IQ tests than White Americans score.")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score the same on IQ tests as White Americans score.")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (IQbw=="On average, Black Americans score lower on IQ tests than White Americans score.")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are more intelligent than White Americans are.")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are equally as intelligent as White Americans are.")
ci mean IQestimate if (IQMath_DO=="testIQ1" | IQMath_DO=="testIQ2") & (INTELbw=="On average, Black Americans are less intelligent than White Americans are.")

***

ci mean testMATH 
ci mean testMATH if (D_IDE=="Extremely liberal" | D_IDE=="Liberal" | D_IDE=="Slightly liberal")
ci mean testMATH if (D_IDE=="Extremely conservative" | D_IDE=="Conservative"| D_IDE=="Slightly conservative")
ci mean testMATH if (IQbw=="On average, Black Americans score higher on IQ tests than White Americans score.")
ci mean testMATH if (IQbw=="On average, Black Americans score the same on IQ tests as White Americans score.")
ci mean testMATH if (IQbw=="On average, Black Americans score lower on IQ tests than White Americans score.")
ci mean testMATH if (INTELbw=="On average, Black Americans are more intelligent than White Americans are.")
ci mean testMATH if (INTELbw=="On average, Black Americans are equally as intelligent as White Americans are.")
ci mean testMATH if (INTELbw=="On average, Black Americans are less intelligent than White Americans are.")

sum female educ age DEM GOP if IQ50==1 | IQ50==0
